package acwing.模拟;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 * 错误票据
 *
 * @author yang
 * @date 2021/11/25
 */
public class 错误票据 {

    static int[] a = new int[100010];
    static int k = 0;

    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(bf.readLine());
        while (n-- > 0) {
            String[] s = bf.readLine().split(" ");
            for (int i = 0; i < s.length; i++) {
                a[k++] = Integer.parseInt(s[i]);
            }
            Arrays.sort(a,0,k);
        }
        int res1 = -1; //断号(只会断一次)
        int res2 = -1; //重号
        for (int i = 1; i < k; i++) {
            if (a[i] == a[i - 1]) res2 = a[i];
            else if (a[i] == a[i - 1] + 2) res1 = a[i] - 1;
        }
        System.out.println(res1 + " " + res2);
    }
}
